package monpkg.rmi;

/**
 * @author Yannick Bouchot
 * @author Jonathan Romero
 */

import java.io.File;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class Server {
/**
 * Cette classe permet de lier les telecommande avec les factory correspondantes
 * @param args
 * @throws MalformedURLException
 * @throws AlreadyBoundException
 */
	public static void main(String[] args) throws MalformedURLException, AlreadyBoundException {

		try {
			String x = (new File("java.policy")).getAbsolutePath();
			System.setProperty("java.security.policy", x);
			
			
			Registry r = LocateRegistry.createRegistry(1099);
			r = LocateRegistry.getRegistry("localhost", 1099);
			
			System.setSecurityManager (new SecurityManager());
			
			
			r.rebind("addressFactory" , new FAddressImpl());
			System.out.println("address factory bind");
			
			r.rebind("studentFactory" , new FStudentImpl());
			System.out.println("student factory bind");
			
			r.rebind("promotionFactory" , new FPromotionImpl());
			System.out.println("promotion factory bind");
			
			r.rebind("adminFactory" , new FAdminImpl());
			System.out.println("admin factory bind");
			
			r.rebind("sessionFactory" , new FSessionImpl());
			System.out.println("session factory bind");
			
			//FAnnuaireImpl annuaireFactory = new FAnnuaireImpl();
			r.rebind("annuaireDAO" , new FAnnuaireImpl());
			System.out.println("annuaire DAO factory bind");

		} catch (RemoteException e) {
			System.out.println("Erreur bind");
			e.printStackTrace();
		}
		

	}

}
